package com.ufrn_access;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SigaaConfsActivity extends Activity {
	
	public static final String PREFS_NAME = "MyPrefsFile";
	static SharedPreferences settings;
	SharedPreferences.Editor editor;
	private String username;
	private String password;
	private EditText usernameEditText;
	private EditText passwordEditText;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sigaa_confs);

		settings = getSharedPreferences(PREFS_NAME,0);
		editor = settings.edit();

		username = settings.getString("username", "");
		password = settings.getString("password", "");

		usernameEditText = (EditText) findViewById(R.id.sigaaConfs_editTextUsername);
		passwordEditText = (EditText) findViewById(R.id.sigaaConfs_editTextPassword);
		Button salvar_button = (Button) findViewById(R.id.sigaaConfs_buttonSalvar);
		Button cancelar_button = (Button) findViewById(R.id.sigaaConfs_buttonCancelar);

		salvar_button.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				editor.putString("username", usernameEditText.getText().toString());
				editor.putString("password", passwordEditText.getText().toString());
				editor.commit();
				finish();
				}
		});
		
		cancelar_button.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				finish();
			}
		});

	}
	
	
	@Override
	protected void onStart() {
		usernameEditText.setText(username);
		passwordEditText.setText(password);
		super.onRestart();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
